<template>
    <van-list v-model="dataset.loading" :finished="dataset.finished" finished-text="没有更多了" @load="requestDatasetOperate">
        <normal-order-list v-for="(item, index) in dataset.items" :key="index"
            @eventOnDeleteItem="eventDeleteItemOperate" :ibase="item.base" :dataset="item.items" class="order-list-items"
        />
    </van-list>
</template>

<script>
    import { List } from 'vant';

    import NormalOrderList from '../../components/currency/order-item/normal-list-stock-out-verify.vue';

    export default {
        components: {
            [List.name]: List,
            NormalOrderList
        },
        data() {
            return {
                dataset: {
                    loading: false, finished: false,
                    page: 0, limit: 30,
                    items: []
                }
            }
        },
        methods: {
            requestDatasetOperate() {
                var url = '/api/home/order/getlist',
                    params = {
                        page: this.dataset.page,
                        list_rows: this.dataset.limit,
                        otype: 1, status: 3,
                        token: this.$store.state.options.user.token
                    };
                    
                this.$util.postRequestInterface(url, params, (res) => {
                    // console.log(res);

                    if(res.data.data) {
                        this.dataset.page++;

                        for(let x of res.data.data) {
                            this.dataset.items.push({
                                base: {
                                    number: x.ordernumber,
                                    amount: x.price,
                                    oda: x
                                },
                                items: [{
                                    title: x.detail[0].garbagename,
                                    number: x.detail[0].weighting_num,
                                    unit: 'kg',
                                    time: this.$moment(x.create_time * 1000).format('YYYY-MM-DD HH:mm:ss'),
                                }]
                            });
                        }
                        
                        if (this.dataset.items.length >= res.data.count) {
                            this.dataset.finished = true;
                        }
                    } else {
                        this.dataset.finished = true;
                    }
                    this.dataset.loading = false;
                });
            },
            eventDeleteItemOperate(index) {
                this.dataset.items.splice(index, 1);
                this.$toast('操作成功');
            }
        }
    }
</script>

<style scoped lang="scss">
    .order-list-items {
        padding: 0.5rem 1rem 0rem;
    }
</style>